package cn.yunhe.service;

import cn.yunhe.dao.IGoodsDao;
import cn.yunhe.entity.Goods;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class IGoodsService {

    //新增快递
    public int addGoods(Goods goods){
        int flag=0;
           SqlSession session= SqlSessionFactoryUtil.getSqlSession();
       try {
           IGoodsDao iGoodsDao=session.getMapper(IGoodsDao.class);
            flag= iGoodsDao.addGoods(goods);
           session.commit();
           return flag;
       }catch (Exception e){
           e.printStackTrace();
       }finally {
           session.close();
       }
       return flag;
    }


    //查询商品总条数
    public int getCount(){
        int count=0;
        SqlSession session= SqlSessionFactoryUtil.getSqlSession();
        try {
            IGoodsDao iGoodsDao=session.getMapper(IGoodsDao.class);
            count=iGoodsDao.getCount();
            return count;
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;

    }


    public List<Goods> queryAllGoods(){
        List<Goods> glist=null;
        SqlSession session= SqlSessionFactoryUtil.getSqlSession();
       try {
           IGoodsDao iGoodsDao=session.getMapper(IGoodsDao.class);
          glist= iGoodsDao.queryAllGoods();
       }catch (Exception e){
           e.printStackTrace();
       }finally {
           session.close();
       }
          return glist;
    }


}
